package com.ssy.lingxi.member.merchant.controller.feign;

import com.ssy.lingxi.common.model.dto.MemberAndRoleIdDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.request.*;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.response.*;
import com.ssy.lingxi.member.merchant.service.feign.IMemberFeignService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 内部接口 - 会员查询服务
 * @author 万宁
 * @version 2.0.0
 * @date 2020-08-11
 */
@RestController
@RequestMapping("/member/feign")
public class MemberFeignController {

    @Resource
    private IMemberFeignService memberFeignService;

    /**
     * 新增会员支付策略 - 查询作为服务提供者的会员信息列表
     * 由于接口参数有嵌套类，Feign发送Get请求的时候反序列化接口参数会报错，所以改为Post请求
     * @param pageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/pay/page")
    public Wrapper<PageData<MemberFeignPayProviderResultVO>> findPayProviderMembers(@RequestBody @Valid MemberFeignPayProviderVO pageVO) {
        return memberFeignService.findPayProviderMembers(pageVO);
    }

    /**
     * 新增会员支付策略 - 选择适用会员
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/pay/provider/page", method = RequestMethod.POST)
    Wrapper<PageData<MemberFeignPayProviderResultVO>> pageNewPayProviderMembers(@RequestBody @Valid MemberFeignPayProviderExcludeVO pageVO) {
        return memberFeignService.pageNewPayProviderMembers(pageVO);
    }

    /**
     * 模板服务 - 模糊查询会员信息列表
     * @param listVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/listname", method = RequestMethod.GET)
    public Wrapper<List<MemberFeignListResultVO>> findMembersFromTemplateService(@Valid MemberFeignListVO listVO) {
        return memberFeignService.findMembersFromTemplateService(listVO);
    }

    /**
     * 根据会员Id和角色Id，查询上属会员列表（不区分企业会员、渠道会员）
     * <p>其中等级为当前会员在其上级会员和上级会员角色下的等级</p>
     * @param feignVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/upper/list")
    public Wrapper<List<MemberFeignQueryVO>> listUpperMembers(@RequestBody @Valid MemberFeignVO feignVO) {
        return memberFeignService.listUpperMembers(feignVO);
    }

    /**
     * 根据会员id和角色id，查询上级“渠道会员”列表
     * @param feignVO 接口参数
     * @return 查询结果
     */
    @RequestMapping("/upper/channel/list")
    public Wrapper<List<MemberFeignRoleIdAndNameVO>> listUpperChannelMembers(@RequestBody @Valid MemberFeignVO feignVO) {
        return memberFeignService.listUpperChannelMembers(feignVO);
    }

    /**
     * 根据会员Id和角色Id，查询下属角色类型为“服务消费者”的会员列表（不区分企业会员、渠道会员）
     * <p>其中等级为下级会员和角色在当前会员和角色下的等级</p>
     * @param feignVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/lower/list")
    public Wrapper<List<MemberFeignQueryVO>> listLowerMembers(@RequestBody @Valid MemberFeignSubVO feignVO) {
        return memberFeignService.listLowerMembers(feignVO);
    }

    /**
     * 根据会员Id和角色Id，查询“审核通过”的下级会员列表（不区分会员类型、角色类型）
     * <p>返回结果中的等级为下级会员和角色在当前会员和角色下的等级</p>
     * @param feignVO 接口参数
     * @return 查询结果
     */
    @RequestMapping("/lower/all/list")
    public Wrapper<List<MemberFeignQueryVO>> listAllLowerMembers(@RequestBody @Valid MemberFeignVO feignVO) {
        return memberFeignService.listAllLowerMembers(feignVO);
    }

    /**
     * 根据会员Id和角色Id，查询“审核通过”的下级会员列表（角色类型为服务提供者）
     * <p>返回结果中的等级为下级会员和角色在当前会员和角色下的等级</p>
     * @param feignVO 接口参数
     * @return 查询结果
     */
    @RequestMapping("/lower/subProvider/list")
    public Wrapper<List<MemberFeignQueryVO>> listSubProviderLowerMembers(@RequestBody @Valid MemberFeignVO feignVO) {
        return memberFeignService.listSubProviderLowerMembers(feignVO);
    }

    /**
     * 根据会员Id、角色Id、上级会员Id、上级会员角色Id，查询会员信息
     * <p>其中等级为当前会员在其上级会员和上级会员角色下的等级</p>
     * @param feignVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/current/get")
    public Wrapper<MemberFeignQueryVO> getMemberInfo(@RequestBody @Valid MemberRelationFeignVO feignVO) {
        return memberFeignService.getMemberInfo(feignVO);
    }

    /**
     * 根据会员Id，查询会员注册信息
     * @param idVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/register/get")
    public Wrapper<MemberFeignRegisterQueryVO> getMemberRegisterInfo(@RequestBody @Valid MemberFeignIdVO idVO) {
        return memberFeignService.getMemberRegisterInfo(idVO);
    }

    /**
     * 根据会员Id列表，查询具有“服务提供者”角色类型的会员信息
     * @param queryVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/batch/byids")
    public Wrapper<List<MemberFeignBatchByIdQueryVO>> batchFindMembersByIdList(@RequestBody @Valid MemberFeignBatchByIdVO queryVO) {
        return memberFeignService.batchFindMembersByIdList(queryVO);
    }

    /**
     * 根据会员Id列表，查询具有“服务提供者”角色类型的“平台会员”信息
     * @param idsVO 接口参数
     * @return 查询结果
     */
    @RequestMapping("/batch/shop/byids")
    public Wrapper<List<MemberFeignShopQueryVO>> batchFindServiceProviderMemberByIdList(@RequestBody @Valid MemberFeignIdsVO idsVO) {
        return memberFeignService.batchFindServiceProviderMemberByIdList(idsVO);
    }

    /**
     * 根据会员名称，查询具有“服务提供者”角色类型的企业会员、企业个人会员的Id列表
     * @param nameVO 接口参数
     * @return 查询结果
     */
    @RequestMapping("/platform/byname")
    public Wrapper<MemberFeignIdsResultVO> findMerchantAndProviderMemberIdListByName(@RequestBody @Valid MemberFeignNameVO nameVO) {
        return memberFeignService.findMerchantAndProviderMemberIdListByName(nameVO);
    }

    /**
     * 根据会员Id、角色Id查询平台会员信息
     * <p>其中等级为当前会员的平台等级</p>
     * @param memberFeignVOList 接口参数
     * @return 查询结果
     **/
    @RequestMapping("/platform/list")
    public Wrapper<List<MemberFeignQueryVO>> listPlatformMembers(@RequestBody @Valid List<MemberFeignVO> memberFeignVOList) {
        return memberFeignService.listPlatformMembers(memberFeignVOList);
    }

    /**
     * 根据会员Id和Aes加密后支付密码，校验支付密码
     * @param checkVO 接口参数
     * @return 查询结果
     */
    @RequestMapping("/paypsw/check")
    public Wrapper<MemberFeignPayPswCheckResultVO> checkMemberPayPassword(@RequestBody @Valid MemberFeignPayPswCheckVO checkVO) {
        return memberFeignService.checkMemberPayPassword(checkVO);
    }

    /**
     * 批量查询会员Logo
     * @param memberIds 会员id列表
     * @return 查询结果
     */
    @RequestMapping("/logo/list")
    public Wrapper<List<MemberFeignLogoVO>> getMemberLogos(@RequestBody List<Long> memberIds) {
        return memberFeignService.getMemberLogos(memberIds);
    }

    /**
     * 根据会员ID批量查询IM客服用户
     * @param memberIds 会员id列表
     * @return 查询结果
     */
    @RequestMapping("/im/list")
    public Wrapper<List<MemberFeignImUserVO>> getImUsers(@RequestBody List<Long> memberIds) {
        return memberFeignService.getImUsers(memberIds);
    }

    /**
     * 根据用户ID批量查询用户信息
     * @param userIds 用户id列表
     * @return 查询结果
     */
    @RequestMapping("/user/list")
    public Wrapper<List<MemberFeignUserVO>> getUsers(@RequestBody List<Long> userIds) {
        return memberFeignService.getUsers(userIds);
    }

    /**
     * 批量查询角色名称
     * @param roleIds 角色id列表
     * @return 查询结果
     */
    @RequestMapping(value = "/role/list", method = RequestMethod.POST)
    public Wrapper<List<MemberFeignRoleVO>> getRoles(@RequestBody List<Long> roleIds) {
        return memberFeignService.getRoles(roleIds);
    }

    /**
     * 订单服务，查询流程规则适用会员列表
     * @param feignVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/platform/find", method = RequestMethod.POST)
    public Wrapper<List<MemberFeignPageQueryVO>> findPlatformMembers(@RequestBody @Valid List<MemberFeignVO> feignVO) {
        return memberFeignService.findPlatformMembers(feignVO);
    }

    /**
     * 订单服务，商户支付参数配置，查询平台服务提供者企业会员列表
     * @param paymentVO 接口参数
     * @return 查询结果
     **/
    @RequestMapping(value = "/merchant/provider/list", method = RequestMethod.POST)
    public Wrapper<List<MemberFeignPageQueryVO>> findProviderMerchant(@RequestBody @Valid MemberFeignPaymentVO paymentVO) {
        return memberFeignService.findProviderMerchant(paymentVO);
    }

    /**
     * 查询是否下级会员
     * @param feignVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/lower/inquiry", method = RequestMethod.POST)
    public Wrapper<Boolean> isSubMember(@RequestBody @Valid MemberRelationFeignVO feignVO) {
        return memberFeignService.isSubMember(feignVO);
    }

    /**
     * 能力中心 - 营销服务, 查询下级会员适用会员
     * @param memberAndUpperMembersVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/lower/suitableMember/list", method = RequestMethod.POST)
    public Wrapper<List<AtSubMemberSuitableMemberVO>> listAbilitySubMemberSuitableMember(@RequestBody @Valid MemberAndUpperMembersVO memberAndUpperMembersVO) {
        return memberFeignService.listAbilitySubMemberSuitableMember(memberAndUpperMembersVO);
    }

    /**
     * 平台后台 - 营销服务, 查询下级会员适用会员
     * @param memberFeignVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/platform/suitableMember/get", method = RequestMethod.POST)
    public Wrapper<PfSubMemberSuitableMemberVO> getPlatformSubMemberSuitableMember(@RequestBody @Valid MemberFeignVO memberFeignVO) {
        return memberFeignService.getPlatformSubMemberSuitableMember(memberFeignVO);
    }

    /**
     * 模板服务 - 新增或更新店铺
     * @param feignVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/platform/template/update", method = RequestMethod.POST)
    public Wrapper<Void> insertOrUpdateMemberShop(@RequestBody @Valid MemberShopFeignVO feignVO) {
        return memberFeignService.insertOrUpdateMemberShop(feignVO);
    }

    /**
     * 所有服务通用 - 查询平台规则配置
     * @param feignVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/platform/rules", method = RequestMethod.POST)
    public Wrapper<List<MemberRuleDetailVO>> findMemberRules(@RequestBody MemberRuleDetailFeignVO feignVO) {
        return memberFeignService.findMemberRules(feignVO);
    }

    /**
     * 根据会员关系，查询业务员Id
     * @param feignVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/sales/find", method = RequestMethod.POST)
    public Wrapper<List<MemberSalesFeignVO>> findMemberSales(@RequestBody List<MemberFeignRelationVO> feignVO) {
        return memberFeignService.findMemberSales(feignVO);
    }

    /**
     * 筛选角色类型为服务提供者的会员
     * @param members 会员Id和角色Id的缓存实体
     * @return 筛选结果
     */
    @RequestMapping(value = "/screen/user/byRoleType", method = RequestMethod.POST)
    public Wrapper<List<MemberAndRoleIdDTO>> screenMemberUser(@RequestBody List<MemberAndRoleIdDTO> members) {
        return memberFeignService.screenMemberUser(members);
    }
}
